home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / IPSPLIT.ICN < prev    next >
Text File  |  1992-11-26  |  3KB  |  82 lines

  1. ############################################################################
  2. #
  3. #    File:     ipsplit.icn
  4. #
  5. #    Subject:  Program to split Icon program into files
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     June 10, 1988
  10. #
  11. ###########################################################################
  12. #  
  13. #     This progam reads an Icon program and writes each procedure to
  14. #  a separate file. The output file names consist of the procedure
  15. #  name with .icn appended.  If the -g option is specified, any glo-
  16. #  bal, link, and record declarations are written to that file. Oth-
  17. #  erwise they are written in the file for the procedure that
  18. #  immediately follows them.
  19. #  
  20. #     Comments and white space between declarations are attached to
  21. #  the next following declaration.
  22. #  
  23. #  Notes:
  24. #
  25. #     The program only recognizes declarations that start at the
  26. #  beginning of lines.  Comments and interline white space between
  27. #  declarations may not come out as intended.
  28. #  
  29. #     If the -g option is not specified, any global, link, or record
  30. #  declarations that follow the last procedure are discarded.
  31. #  
  32. ############################################################################
  33. #
  34. #  Links: options
  35. #
  36. ############################################################################
  37.  
  38. link options
  39.  
  40. procedure main(args)
  41.    local line, x, i, proctable, proclist, comments, gfile, gname, ofile
  42.    local opts
  43.  
  44.    comments := []
  45.  
  46.    opts := options(args,"g:")
  47.    if gname := \opts["g"] then {
  48.       gfile := open(gname,"w") | stop("*** cannot open ",gname)
  49.       }
  50.  
  51.    proctable := table()
  52.    while line := read() do {
  53.       if line ? {
  54.          ="procedure" &            #  procedure declaration
  55.          tab(many(' ')) &
  56.          proctable[tab(upto('('))] := x := []
  57.          } then {
  58.             while put(x,get(comments))    #  save it
  59.             put(x,line)
  60.             i := 1
  61.             while line := read() do {
  62.                put(x,line)
  63.                if line == "end" then break
  64.                }
  65.             }
  66.                     #  other declarations
  67.          else if \gfile & line ? =("global" | "record" | "link")
  68.          then {
  69.             while write(gfile,get(comments))
  70.             write(gfile,line)
  71.             }
  72.          else put(comments,line)
  73.          }
  74.    while write(\gfile,get(comments))
  75.    proclist := sort(proctable,3)    #  sort procedures
  76.    while x := get(proclist) do {    #  output procedures
  77.       ofile := open(x || ".icn","w") | stop("cannot write ",x,".icn")
  78.       every write(ofile,!get(proclist))
  79.       close(ofile)
  80.       }
  81. end
  82.